package com.highspeed.bdk.gateway.socket.analyze.message.gui.resolver;

import com.highspeed.bdk.gateway.Util;
import com.highspeed.bdk.gateway.socket.analyze.message.gui.base.MessageResolver;

import java.util.Map;

/**
 * 3.13逻辑链路对应物理链路查询的反馈包
 * typedef struct _phyUnderLogicLink
 * {
 * U32 startPortId; //链路起点Id 16-bit rionet id + 16-bit portId
 * U32 endPortId;//链路终点Id  16-bit rionet id + 16-bit portId
 * <p>
 * U16 phyLinkNum; //绑定在此物理链路上的逻辑链路数，只记录端口对
 * U16 oneLinkLen; //一个链路数据的长度用于解释下面的数据
 * <p>
 * SimpleLink physicalLinks[0];//绑定在此物理链路上的逻辑链路集
 * <p>
 * } PhyUnderLogicLinkData;
 */
public class PhyUnderLogicLinkResolver0x0F extends MessageResolver {

    @Override
    protected Map doResolveBody(byte[] response) {
        short rionetId = Util.getShort(response, getOffset());
        offset2();
        logger.info("链路起点 rionetId.........." + rionetId);

        short portId = Util.getShort(response, getOffset());
        offset2();
        logger.info("链路起点 portId..........." + portId);

        rionetId = Util.getShort(response, getOffset());
        offset2();
        logger.info("链路终点 rionetId..........." + rionetId);

        portId = Util.getShort(response, getOffset());
        offset2();
        logger.info("链路终点 portId..........." + portId);

        short phyLinkNum = Util.getShort(response, getOffset());
        offset2();
        logger.info("phyLinkNum..........." + phyLinkNum);

        short oneLinkLen = Util.getShort(response, getOffset());
        offset2();
        logger.info("oneLinkLen..........." + oneLinkLen);

        //逻辑链路的端口对查询的反馈包
        SimpleLinkResolver simpleLinkResolver = new SimpleLinkResolver();
        simpleLinkResolver.setContainer(getContainer());
        for (int i = 0; i < oneLinkLen; i++) {
            logger.info("解析第" + i + "个逻辑链路的端口对查询的反馈包");
            simpleLinkResolver.doResolveBody(response);
        }
        return getContainer();
    }
}
